package com.letsiot.applications.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import com.letsiot.applications.entity.SysOperatorLog;
import com.letsiot.applications.entity.enums.OperatorType;
import com.letsiot.applications.entity.vo.ContainerOpeartionTableVO;
import com.letsiot.applications.entity.vo.ResgistryOpeartionTableVO;
import com.letsiot.applications.repository.SysOperatorLogMapper;
import com.letsiot.applications.service.SysOperatorLogService;
import com.letsiot.common.data.IdUtil;

@Service
public class SysOperatorLogServiceImpl implements SysOperatorLogService {

    @Value("${info.systemId.name}")
    private String systemName;

    @Autowired
    private SysOperatorLogMapper haloSysOperatorLogMapper;

    @Override
    public int save(SysOperatorLog entity) {
        if (entity.getId() == null) {
            entity.setId(IdUtil.getId());
        }
        return haloSysOperatorLogMapper.insertSelective(entity);
    }

    @Override
    public int delete(Long id) {
        return haloSysOperatorLogMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int update(SysOperatorLog entity) {
        return haloSysOperatorLogMapper.updateByPrimaryKeySelective(entity);
    }

    @Override
    public SysOperatorLog findById(Long id) {
        return haloSysOperatorLogMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SysOperatorLog> getAll() {
        return haloSysOperatorLogMapper.getAll();
    }

    @Override
    public Page<SysOperatorLog> getOperatorLog(Date startDate, Date endDate, OperatorType operatorType, Long userId,
            Pageable pageable) {
        return haloSysOperatorLogMapper.getOperatorLog(startDate, endDate, operatorType, userId, pageable);
    }

    @Override
    public Page<ResgistryOpeartionTableVO> registryOperationPage(Pageable pageable, String messageType,
            String operationLogOrOperationName, Date startDate, String endDate, String remark) {
        return haloSysOperatorLogMapper.registryOperationPage(pageable, messageType, operationLogOrOperationName,
                startDate, endDate, remark);
    }

    @Override
    public Page<ContainerOpeartionTableVO> containerOperationPage(Pageable pageable, String operationLogOrOperationName,
            Date startDate, String endDate, String remark) {
        return haloSysOperatorLogMapper.containerOperationPage(pageable, operationLogOrOperationName, startDate,
                endDate, remark);
    }
}
